package crmdna.api.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GoogleLoginServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		
		// redirect to the authorization flow
		String redirectUri = Utils.getRedirectUri(request);
		String onSuccessUrl = request.getParameter("onSuccessUrl");
		String onErrorUrl = request.getParameter("onErrorUrl");
		
		response.sendRedirect(Utils.newFlow().newAuthorizationUrl()
				.setState(request.getParameter("login") + "|" + onSuccessUrl + "|" + onErrorUrl)
				.setRedirectUri(redirectUri).build());
	}
}